<template>
    <LoginHeader></LoginHeader>
    <section class="container">
        <nav class="tab">
            <a href="javascript:;" :class="{ active: hasAccount }" @click="hasAccount = true">
                <i class="iconfont icon-bind" />
                <span>已有小兔鲜账号，请绑定手机</span>
            </a>
            <a href="javascript:;" :class="{ active: !hasAccount }" @click="hasAccount = false">
                <i class="iconfont icon-edit" />
                <span>没有小兔鲜账号，请完善资料</span>
            </a>
        </nav>
        <div class="tab-content" v-if="hasAccount">
          <!-- 绑定手机 -->
          <CallbackBind />
        </div>
        <div class="tab-content" v-else>
          <!-- 完善资料 -->
          <CallbackPatch />
        </div>
    </section>
    <LoginFooter></LoginFooter>
</template>

<script lang="ts" setup name="LoginCallback">
  import LoginHeader from './components/login-header.vue'
  import LoginFooter from './components/login-footer.vue'
  // 已有小兔仙账号,绑定手机号
  import CallbackBind from './components/callback-bind.vue'
  // 没有账号 完善信息
  import CallbackPatch from './components/callback-patch.vue'
  // 导入user模块
  import useStore from '@/store'
  import Message from '@/components/message'
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  const { user } = useStore()
  const hasAccount = ref(true)
  const router = useRouter()
  // 1. 判断用户是否是 QQ 扫码过来的
  const qc = QC.Login as loginObj
  const isLogin = qc.check()
  if (isLogin) {
    // 2. 获取 openId
    qc.getMe(async (openId) => {
      try {
        // 3. 把 openId 传递到后端进行登录
        await user.qqLogin(openId)
        // 登录成功跳转到首页
        router.push('/')
        Message.success('第三方登录功能')
      } catch (e) {
        console.dir(e)
        // 4. 把拿到的结果存储到 Pinia
      }
    })
  }
</script>


<style scoped lang="less">
    .container {
        padding: 25px 0;
    }
    .tab {
        background: #fff;
        height: 80px;
        padding-top: 40px;
        font-size: 18px;
        text-align: center;
        a {
            color: #666;
            display: inline-block;
            width: 350px;
            line-height: 40px;
            border-bottom: 2px solid #e4e4e4;
            i {
                font-size: 22px;
                vertical-align: middle;
            }
            span {
                vertical-align: middle;
                margin-left: 4px;
            }
            &.active {
                color: @xtxColor;
                border-color: @xtxColor;
            }
        }
    }
    .tab-content {
        min-height: 600px;
        background: #fff;
    }
</style>